﻿namespace EFS.RC.SupervisorCentral.Controls
{
	/// <summary>
	/// Interaction logic for Thresholds.xaml
	/// </summary>
	public partial class Thresholds : System.Windows.Window
	{
		// config
		EFS.RC.SupervisorCentral.Common.Config.Sections.Monitoring.Thresholds.All phoneThresholds = null;

		public Thresholds(System.String phoneUri)
		{
			InitializeComponent();

			// th
			phoneThresholds = EFS.RC.SupervisorCentral.Common.Config.Sections.Monitoring.All.Instance.GetForThePhone(phoneUri);
		}

		/// <summary>
		/// Int32 or -1 if invalid
		/// </summary>
		/// <param name="text"></param>
		/// <returns></returns>
		private System.Int32 LimitInt32(System.String text)
		{
			System.Int32 limit = -1;
			if (System.Int32.TryParse(text, out limit))
			{
				return limit;
			}
			return -1;
		}

		/// <summary>
		/// Limit as text
		/// </summary>
		/// <param name="text"></param>
		/// <returns></returns>
		private System.String LimitText(System.Int32 limit)
		{
			if (-1 == limit) { return ""; }
			return limit.ToString();
		}

		private void buttonSave_Click(object sender, System.Windows.RoutedEventArgs e)
		{
			// save
			phoneThresholds.ACD_AvailableCount.OK.Left = LimitInt32(textBoxAvailable1.Text);
			phoneThresholds.ACD_AvailableCount.OK.Right = LimitInt32(textBoxAvailable2.Text);
			phoneThresholds.ACD_AvailableCount.Warning.Left = LimitInt32(textBoxAvailable3.Text);
			phoneThresholds.ACD_AvailableCount.Warning.Right = LimitInt32(textBoxAvailable4.Text);

			phoneThresholds.ACD_BusyInHuntCount.OK.Left = LimitInt32(textBoxBusyInConference1.Text);
			phoneThresholds.ACD_BusyInHuntCount.OK.Right = LimitInt32(textBoxBusyInConference2.Text);
			phoneThresholds.ACD_BusyInHuntCount.Warning.Left = LimitInt32(textBoxBusyInConference3.Text);
			phoneThresholds.ACD_BusyInHuntCount.Warning.Right = LimitInt32(textBoxBusyInConference4.Text);

			phoneThresholds.ACD_LWTSeconds.OK.Left = LimitInt32(textBoxLWT1.Text);
			phoneThresholds.ACD_LWTSeconds.OK.Right = LimitInt32(textBoxLWT2.Text);
			phoneThresholds.ACD_LWTSeconds.Warning.Left = LimitInt32(textBoxLWT3.Text);
			phoneThresholds.ACD_LWTSeconds.Warning.Right = LimitInt32(textBoxLWT4.Text);

			phoneThresholds.ACD_BusyInWrap.OK.Left = LimitInt32(textBoxBusyInWrap1.Text);
			phoneThresholds.ACD_BusyInWrap.OK.Right = LimitInt32(textBoxBusyInWrap2.Text);
			phoneThresholds.ACD_BusyInWrap.Warning.Left = LimitInt32(textBoxBusyInWrap3.Text);
			phoneThresholds.ACD_BusyInWrap.Warning.Right = LimitInt32(textBoxBusyInWrap4.Text);

			phoneThresholds.ACD_BusyNotInHuntCount.OK.Left = LimitInt32(textBoxBusyNotInConferece1.Text);
			phoneThresholds.ACD_BusyNotInHuntCount.OK.Right = LimitInt32(textBoxBusyNotInConferece2.Text);
			phoneThresholds.ACD_BusyNotInHuntCount.Warning.Left = LimitInt32(textBoxBusyNotInConferece3.Text);
			phoneThresholds.ACD_BusyNotInHuntCount.Warning.Right = LimitInt32(textBoxBusyNotInConferece4.Text);

			phoneThresholds.ACD_OfflineCount.OK.Left = LimitInt32(textBoxACDOffline1.Text);
			phoneThresholds.ACD_OfflineCount.OK.Right = LimitInt32(textBoxACDOffline2.Text);
			phoneThresholds.ACD_OfflineCount.Warning.Left = LimitInt32(textBoxACDOffline3.Text);
			phoneThresholds.ACD_OfflineCount.Warning.Right = LimitInt32(textBoxACDOffline4.Text);

			phoneThresholds.NotACD_OnlineCount.OK.Left = LimitInt32(textBoxNonACDOnline1.Text);
			phoneThresholds.NotACD_OnlineCount.OK.Right = LimitInt32(textBoxNonACDOnline2.Text);
			phoneThresholds.NotACD_OnlineCount.Warning.Left = LimitInt32(textBoxNonACDOnline3.Text);
			phoneThresholds.NotACD_OnlineCount.Warning.Right = LimitInt32(textBoxNonACDOnline4.Text);

			phoneThresholds.NotACD_OfflineCount.OK.Left = LimitInt32(textBoxNonACDOffline1.Text);
			phoneThresholds.NotACD_OfflineCount.OK.Right = LimitInt32(textBoxNonACDOffline2.Text);
			phoneThresholds.NotACD_OfflineCount.Warning.Left = LimitInt32(textBoxNonACDOffline3.Text);
			phoneThresholds.NotACD_OfflineCount.Warning.Right = LimitInt32(textBoxNonACDOffline4.Text);

			this.Close();
		}

		private void buttonCancel_Click(object sender, System.Windows.RoutedEventArgs e)
		{
			this.Close();
		}

		private void Window_Loaded(object sender, System.Windows.RoutedEventArgs e)
		{
			textBoxAvailable1.Text = LimitText(phoneThresholds.ACD_AvailableCount.OK.Left);
			textBoxAvailable2.Text = LimitText(phoneThresholds.ACD_AvailableCount.OK.Right);
			textBoxAvailable3.Text = LimitText(phoneThresholds.ACD_AvailableCount.Warning.Left);
			textBoxAvailable4.Text = LimitText(phoneThresholds.ACD_AvailableCount.Warning.Right);

			textBoxBusyInConference1.Text = LimitText(phoneThresholds.ACD_BusyInHuntCount.OK.Left);
			textBoxBusyInConference2.Text = LimitText(phoneThresholds.ACD_BusyInHuntCount.OK.Right);
			textBoxBusyInConference3.Text = LimitText(phoneThresholds.ACD_BusyInHuntCount.Warning.Left);
			textBoxBusyInConference4.Text = LimitText(phoneThresholds.ACD_BusyInHuntCount.Warning.Right);

			textBoxLWT1.Text = LimitText(phoneThresholds.ACD_LWTSeconds.OK.Left);
			textBoxLWT2.Text = LimitText(phoneThresholds.ACD_LWTSeconds.OK.Right);
			textBoxLWT3.Text = LimitText(phoneThresholds.ACD_LWTSeconds.Warning.Left);
			textBoxLWT4.Text = LimitText(phoneThresholds.ACD_LWTSeconds.Warning.Right);

			textBoxBusyInWrap1.Text = LimitText(phoneThresholds.ACD_BusyInWrap.OK.Left);
			textBoxBusyInWrap2.Text = LimitText(phoneThresholds.ACD_BusyInWrap.OK.Right);
			textBoxBusyInWrap3.Text = LimitText(phoneThresholds.ACD_BusyInWrap.Warning.Left);
			textBoxBusyInWrap4.Text = LimitText(phoneThresholds.ACD_BusyInWrap.Warning.Right);

			textBoxBusyNotInConferece1.Text = LimitText(phoneThresholds.ACD_BusyNotInHuntCount.OK.Left);
			textBoxBusyNotInConferece2.Text = LimitText(phoneThresholds.ACD_BusyNotInHuntCount.OK.Right);
			textBoxBusyNotInConferece3.Text = LimitText(phoneThresholds.ACD_BusyNotInHuntCount.Warning.Left);
			textBoxBusyNotInConferece4.Text = LimitText(phoneThresholds.ACD_BusyNotInHuntCount.Warning.Right);

			textBoxACDOffline1.Text = LimitText(phoneThresholds.ACD_OfflineCount.OK.Left);
			textBoxACDOffline2.Text = LimitText(phoneThresholds.ACD_OfflineCount.OK.Right);
			textBoxACDOffline3.Text = LimitText(phoneThresholds.ACD_OfflineCount.Warning.Left);
			textBoxACDOffline4.Text = LimitText(phoneThresholds.ACD_OfflineCount.Warning.Right);

			textBoxNonACDOnline1.Text = LimitText(phoneThresholds.NotACD_OnlineCount.OK.Left);
			textBoxNonACDOnline2.Text = LimitText(phoneThresholds.NotACD_OnlineCount.OK.Right);
			textBoxNonACDOnline3.Text = LimitText(phoneThresholds.NotACD_OnlineCount.Warning.Left);
			textBoxNonACDOnline4.Text = LimitText(phoneThresholds.NotACD_OnlineCount.Warning.Right);

			textBoxNonACDOffline1.Text = LimitText(phoneThresholds.NotACD_OfflineCount.OK.Left);
			textBoxNonACDOffline2.Text = LimitText(phoneThresholds.NotACD_OfflineCount.OK.Right);
			textBoxNonACDOffline3.Text = LimitText(phoneThresholds.NotACD_OfflineCount.Warning.Left);
			textBoxNonACDOffline4.Text = LimitText(phoneThresholds.NotACD_OfflineCount.Warning.Right);
		}
	}
}